<%@page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@page import="com.cseg674.datamanagement.adler.*" %>
<%@page import="com.hp.hpl.jena.util.iterator.ExtendedIterator" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

<%@ include file="/includes/head.jsp" %>

<script type="text/javascript">
function handlePrjSelect(item) {
	var index = item.selectedIndex;
	var value = item[index].text;
	
	if (value !== "Select a project...") {
		document.Index.button.disabled = false;
	} else {
		document.Index.button.disabled = true;
	}
}
</script>

<body>

<div id="page">

	<%@ include file="/includes/header.jsp" %>
	
	<div id="menulinks">
		<a href="index.jsp"><span>Home</span></a>	
		<div class="menulines"></div>
		<a href="about.jsp"><span>About</span></a>
		<div class="menulines"></div>
		<a href="entry.jsp"><span>Entry</span></a>
		<div class="menulines"></div>
		<a class="active" href="query.jsp"><span>Query</span></a>
		<div class="menulines"></div>
		<% if(null == session.getAttribute("username")) { %>
			<a href="login.jsp"><span>Login</span></a>
		<% } else { %>  
			<a href="logout.jsp"><span>Logout</span></a>
		<% } %>
		<div class="menulines"></div>
		<a href="engineers.jsp"><span>Engineers</span></a>
		<div class="menulines"></div>
	</div>
	
	<div id="mainarea">
		<div id="contentarea">
			<h2><img src="images/search_sm.png" alt="Query" /> &nbsp; Query</h2>
			<div id="query" class="content">
			<% 
				HttpSession session_login = request.getSession(true);
				String msg = (String) session_login.getAttribute("msg");
				if(msg != null){ out.println("<p>" + msg + "</p>"); }
			 %>
				<p>Here in the Data Query page, users can run SPARQL queries against all projects submitted using the drop down menu below.</p>
				<form name="Index" action="ExtractorServlet" method="POST">
					<p>
						<img src="images/next.png" alt="Select a Project" />
						<select id="PrjName" name="PrjName" class="styled" onChange="handlePrjSelect(this)">
						<option>Select a project...</option>
						<%
							Adler adler  = (Adler)getServletContext().getAttribute("adler");
							try{
								if(adler == null){
									adler = new Adler();
									getServletContext().setAttribute("adler", adler);
								}
								ExtendedIterator xIt = adler.listProjects();
								while(xIt.hasNext()){
									String prjName = (String)xIt.next(); %>
									<option value='<%= prjName %>'><%= prjName %></option>
						<%  	}
							}
							catch(AdlerException aex){
								System.out.println("AdlerException: "+aex.getMessage());
							}
							catch(Exception ex){
								ex.printStackTrace();
							}
						%>
						</select>
						&nbsp;&nbsp;&nbsp;
						<input disabled name="button" type="submit" value="Submit">
					</p>
				</form>
			
			</div>

		</div>
	
		<%@ include file="/includes/sidebar.jsp" %>
		<%@ include file="/includes/footer.jsp" %>
	</div>

</body>

</html>
